package com.Sun.Helper;

import javax.swing.text.StyledDocument;

public class encryptHelper {
	/**
	 * 将keyword加密为16位长的随机数
	 * @param sk
	 * @param keyword
	 * @return
	 */
	public static int F(int sk,String keyword)
	{
		int cap=1<<16;
		int result = 0;  
        int len = keyword.length();  
        for (int i = 0; i < len; i++) {  
            result = sk * result + keyword.charAt(i);  
        }  
        return (cap - 1) & result;  
	}
	/**
	 *  将value转化为32为的整数
	 * @param value
	 * @return
	 */
	public static int U(String value,int di)
	{
		int cap=1<<32;
		int result=0;
		int seed=0;
		int len=value.length();
		if(di==0)
		{
			seed=61;
		}
		else{
			seed=37;
		}
		for(int i=0;i<len;i++)
		{
			result=seed* result+value.charAt(i);
		}
		return result;
	}
	public static void main(String[]args)
	{
		String keyword="yuanqiongiqon";
		int sk=31;
		int f=F(sk, keyword);
		System.out.println(f);
		f=U(new Integer(f).toString(), 1);
		System.out.println(f);
	}
	

}
